#include "threadPool.h"
#include"sendMsg.h"
//保证一次sendMsg对应一次recvMsg
int sendMsg(int sockfd,const char *buf)
{
    train message;
    message.length=strlen(buf);
    memcpy(message.data,buf,message.length);
    int ret=send(sockfd,&message,sizeof(int)+message.length,0);
    if(ret==0){
        return 0;
    }
    if(ret==-1){
        return -1;
    }
    return 1;
}
int recvMsg(int sockfd,char *buf)
{
    train message;
    int ret=recv(sockfd,&message.length,sizeof(int),MSG_WAITALL);
    if(ret==0){
        return 0;
    }
    if(ret==-1){
        return -1;
    }
    ret=recv(sockfd,buf,message.length,MSG_WAITALL);
    if(ret==0){
        return 0;
    }
    if(ret==-1){
        return -1;
    }
    return 1;
}

